package com.example.demo.utils

import android.content.Context
import android.content.res.Configuration
import com.example.demo.R
import com.github.jokar.multilanguages.library.MultiLanguage
import com.google.android.material.tabs.TabLayout
import java.util.*

object LocalManageUtil {
    const val TAG = "LocalManagerUtil"

    fun getSystemLocale(context: Context): Locale {
        return SPUtil.getInstance(context).systemCurrentLocale
    }

    fun getSelectLanguage(context: Context):String{
        return when(SPUtil.getInstance(context).selectLanguage){
            0 -> context.getString(R.string.language_auto)
            1 -> context.getString(R.string.language_cn)
            2 -> context.getString(R.string.language_traditional)
            else -> context.getString(R.string.language_en)
        }
    }

    /**
     * 获取选择的语言设置
     */
    fun getSetLanguageLocale(context: Context):Locale{
        return when(SPUtil.getInstance(context).selectLanguage){
            0 -> getSystemLocale(context)
            1 -> Locale.CHINA
            2 -> Locale.TAIWAN
            else -> Locale.ENGLISH
        }
    }

    fun saveSystemCurrentLanguage(context: Context){
        SPUtil.getInstance(context).systemCurrentLocale = MultiLanguage.getSystemLocal(context)
    }

    /**
     * 保存系统语言
     */
    fun saveSystemCurrentLanguage(context: Context, newConfig:Configuration){
        SPUtil.getInstance(context).systemCurrentLocale = MultiLanguage.getSystemLocal(newConfig)
    }

    fun saveSelectLanguage(context: Context, select:Int){
        SPUtil.getInstance(context).saveLanguage(select)
        MultiLanguage.setApplicationLanguage(context)
    }
}